﻿using System.Collections.Generic;
using System.Linq;
using System.Threading;
using NetService.Parser;

namespace NetService
{
    public static class WeekTasks
    {
        private const string NEWSWEEK_URL = @"http://www.newsweek.com/tag/politics.html?start={0}";
        private const int PAGE_COUNT = 277;

        public static IDictionary<string, string> GetTasks()
        {
            var res = new Dictionary<string, string>();

            for (int i = 0; i < PAGE_COUNT; i++)
            {
                var url = string.Format(NEWSWEEK_URL, i * 10);

                var text = PageService.GetPage(url);

                var pages = HtmlPagesParser.GetPages(text);

                foreach (var resIter in pages)
                {
                    if (!res.ContainsKey(resIter.Key))
                        res.Add(resIter.Key, resIter.Value);
                }

                Thread.Sleep(1000);
            }

            return res;
        }
    }
}
